import * as OAuthApi from '../../api/auth';
import { setBladeToken } from '../../utils/token-storage';

async function getBladeToken(userName, password, baseUrl) {
  try {
    const result = await OAuthApi.getBladeToken(userName, password, baseUrl);
    console.log('获取到的Token ==>', result);
    const token = result.data.access_token;
    !!token && setBladeToken(token);
  } catch (e) {
    console.log('获取Token失败 ==>', e);
  }
}

const TokenGenerator = {
  getBladeToken,
};

export default TokenGenerator;
